package com.zhang.designmode.wangzheng_design_mode.T48.dynamicProxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @Author: zxz
 * @DateTime: 2022/3/1 16:31
 * @Description: TODO
 */
public class MonitorProxy implements InvocationHandler {

    private Object proxyObject;
    private UserController userController = new UserController();

    public MonitorProxy() {
    }

    public MonitorProxy(Object proxyObject) {
        this.proxyObject = proxyObject;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        long l1 = System.currentTimeMillis();
        Object invoke = method.invoke(proxyObject, args);
        long l2 = System.currentTimeMillis();
        System.out.println("耗时:"+(l2-l1));
        userController.login();
        return invoke;
    }
}
